<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信访分析系统 - 区域分析</title>
    <script src="./static/vendor/js/tailwindcss-3.4.17.js"></script>
    <link rel="stylesheet" href="./static/vendor/css/font-awesome-6.4.0.all.min.css">
    <script src="./static/vendor/js/chart-4.5.0.js"></script>
    <style>
        :root {
            --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f8fafc;
        }

        /* 自定义滚动条 */
        .custom-scrollbar::-webkit-scrollbar {
            width: 6px;
        }
        .custom-scrollbar::-webkit-scrollbar-track {
            background: #f1f5f9;
            border-radius: 3px;
        }
        .custom-scrollbar::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 3px;
        }
        .custom-scrollbar::-webkit-scrollbar-thumb:hover {
            background: #94a3b8;
        }

        /* 侧边栏动画 */
        .sidebar {
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .sidebar-collapsed {
            width: 64px !important;
        }
        .sidebar-expanded {
            width: 15% !important;
        }

        /* 文本淡入淡出 */
        .fade-text {
            transition: opacity 0.3s ease-in-out;
        }
        .fade-text.hidden {
            opacity: 0;
            pointer-events: none;
        }

        /* 导航菜单项 */
        .nav-item {
            transition: all 0.3s ease;
            position: relative;
        }
        .nav-item::after {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 0;
            background: var(--primary-gradient);
            border-radius: 0 2px 2px 0;
            transition: height 0.3s ease;
        }
        .nav-item:hover::after,
        .nav-item.active::after {
            height: 70%;
        }
        .nav-item:hover {
            background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, transparent 100%);
        }
        .nav-item.active {
            background: linear-gradient(90deg, rgba(102, 126, 234, 0.15) 0%, transparent 100%);
            color: #667eea;
        }

        /* 区域卡片 */
        .region-card {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .region-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
        }
        .region-card.selected {
            border-color: #667eea;
            background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
        }

        /* 图表容器 */
        .chart-container {
            position: relative;
            height: 400px;
        }

        /* 时间标签 */
        .time-tag {
            transition: all 0.2s ease;
        }
        .time-tag:hover {
            transform: scale(1.05);
        }
        .time-tag.active {
            background: var(--primary-gradient);
            color: white;
        }

        /* 统计数据项 */
        .stat-item {
            transition: all 0.3s ease;
        }
        .stat-item:hover {
            background: rgba(102, 126, 234, 0.05);
            transform: translateX(5px);
        }
    </style>
</head>
<body class="bg-slate-50">
    <div class="flex h-screen overflow-hidden">
        <!-- 左侧边栏 -->
        <div id="sidebar" class="sidebar sidebar-expanded bg-white shadow-xl border-r border-slate-200 flex flex-col">
            <!-- 应用标题 -->
            <div class="p-6 border-b border-slate-200">
                <div class="flex items-center justify-between">
                    <div class="flex items-center space-x-3">
                        <div class="w-10 h-10 rounded-xl bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center shadow-lg">
                            <i class="fas fa-file-contract text-white text-lg"></i>
                        </div>
                        <div class="fade-text">
                            <h1 class="font-bold text-xl bg-gradient-to-r from-indigo-600 to-purple-600 bg-clip-text text-transparent">信访分析系统</h1>
                            <p class="text-xs text-slate-500">智能分析平台</p>
                        </div>
                    </div>
                    <button id="sidebarToggle" class="p-2 rounded-lg hover:bg-slate-100 transition-colors">
                        <i class="fas fa-bars text-slate-600"></i>
                    </button>
                </div>
            </div>

            <!-- 导航菜单 -->
            <div class="flex-1 overflow-y-auto custom-scrollbar">
                <nav class="p-4">
                    <ul class="space-y-2">
                        <li>
                            <a href="dashboard.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-dashboard text-lg"></i>
                                <span class="fade-text font-medium">仪表盘</span>
                            </a>
                        </li>
                        <li>
                            <a href="analysis-results.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-search text-lg"></i>
                                <span class="fade-text font-medium">分析结果</span>
                            </a>
                        </li>
                        <li>
                            <a href="petition-statistics.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-chart-bar text-lg"></i>
                                <span class="fade-text font-medium">信访件统计</span>
                            </a>
                        </li>
                        <li>
                            <a href="regional-analysis.html" class="nav-item active flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-map text-lg"></i>
                                <span class="fade-text font-medium">区域分析</span>
                            </a>
                        </li>
                        <li>
                            <a href="coordinate-analysis.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-map-marker-alt text-lg"></i>
                                <span class="fade-text font-medium">经纬度分析</span>
                            </a>
                        </li>
                        <li>
                            <a href="key-issues.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-exclamation-triangle text-lg"></i>
                                <span class="fade-text font-medium">重点问题分析</span>
                            </a>
                        </li>
                        <li>
                            <a href="report-generation.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-file-alt text-lg"></i>
                                <span class="fade-text font-medium">生成报告</span>
                            </a>
                        </li>
                        
                        <!-- 管理员功能 -->
                        <li class="pt-4 mt-4 border-t border-slate-200">
                            <p class="fade-text text-xs text-slate-500 font-semibold px-4 mb-2">管理员功能</p>
                        </li>
                        <li>
                            <a href="ai-analysis.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-robot text-lg"></i>
                                <span class="fade-text font-medium">AI分析功能</span>
                            </a>
                        </li>
                        <li>
                            <a href="system-settings.html" class="nav-item flex items-center space-x-3 px-4 py-3 rounded-lg cursor-pointer">
                                <i class="fas fa-cog text-lg"></i>
                                <span class="fade-text font-medium">系统设置</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>

            <!-- 用户信息 -->
            <div class="p-4 border-t border-slate-200">
                <div class="flex items-center space-x-3">
                    <div class="w-12 h-12 rounded-full bg-gradient-to-br from-emerald-400 to-cyan-500 flex items-center justify-center shadow-lg">
                        <i class="fas fa-user text-white text-lg"></i>
                    </div>
                    <div class="fade-text flex-1">
                        <p class="font-semibold text-slate-800">管理员</p>
                        <p class="text-xs text-slate-500">admin@example.com</p>
                    </div>
                    <div class="relative">
                        <button id="userMenuBtn" class="fade-text p-2 rounded-lg hover:bg-slate-100 transition-colors">
                            <i class="fas fa-chevron-down text-slate-600"></i>
                        </button>
                        <!-- 下拉菜单 -->
                        <div id="userMenu" class="hidden absolute right-0 bottom-full mb-2 w-48 bg-white rounded-lg shadow-lg border border-slate-200">
                            <a href="#" class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-100 rounded-t-lg">
                                <i class="fas fa-user-circle mr-2"></i>个人中心
                            </a>
                            <a href="#" class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-100">
                                <i class="fas fa-cog mr-2"></i>账户设置
                            </a>
                            <hr class="my-1 border-slate-200">
                            <a href="login.html" class="block px-4 py-2 text-sm text-slate-700 hover:bg-slate-100 rounded-b-lg">
                                <i class="fas fa-sign-out-alt mr-2"></i>退出登录
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 主内容区 -->
        <div class="flex-1 flex flex-col overflow-hidden">
            <!-- 顶部栏 -->
            <header class="bg-white border-b border-slate-200 px-6 py-4">
                <div class="flex items-center justify-between">
                    <div>
                        <h2 class="text-2xl font-bold text-slate-800">区域分析</h2>
                        <p class="text-sm text-slate-500">按区域维度统计分析信访数据</p>
                    </div>
                    <div class="flex items-center space-x-4">
                        <button class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                            <i class="fas fa-download mr-2"></i>导出分析
                        </button>
                    </div>
                </div>
            </header>

            <!-- 滚动内容区 -->
            <main class="flex-1 overflow-y-auto custom-scrollbar p-6">
                <!-- 筛选条件 -->
                <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6 mb-6">
                    <h3 class="text-lg font-semibold text-slate-800 mb-4">分析条件</h3>
                    
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <!-- 任务结果选择 -->
                        <div>
                            <label class="block text-sm font-medium text-slate-700 mb-2">选择任务结果</label>
                            <select class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <option>全部任务结果</option>
                                <option>任务一 - 2024年1月分析</option>
                                <option>任务二 - 2023年12月分析</option>
                                <option>任务三 - 2023年11月分析</option>
                            </select>
                        </div>

                        <!-- 时间区间 -->
                        <div>
                            <label class="block text-sm font-medium text-slate-700 mb-2">时间区间</label>
                            <div class="flex space-x-2">
                                <input type="date" class="flex-1 px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <input type="date" class="flex-1 px-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                            </div>
                        </div>

                        <!-- 快速选择 -->
                        <div>
                            <label class="block text-sm font-medium text-slate-700 mb-2">快速选择</label>
                            <div class="flex flex-wrap gap-2">
                                <button class="time-tag px-3 py-1 text-sm border border-slate-300 rounded-lg hover:bg-slate-100">本月</button>
                                <button class="time-tag px-3 py-1 text-sm border border-slate-300 rounded-lg hover:bg-slate-100">上月</button>
                                <button class="time-tag px-3 py-1 text-sm border border-slate-300 rounded-lg hover:bg-slate-100">本季度</button>
                                <button class="time-tag active px-3 py-1 text-sm border border-slate-300 rounded-lg">本年度</button>
                            </div>
                        </div>
                    </div>

                    <div class="flex justify-end mt-4">
                        <button class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
                            <i class="fas fa-chart-bar mr-2"></i>开始分析
                        </button>
                    </div>
                </div>

                <!-- 区域选择 -->
                <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6 mb-6">
                    <h3 class="text-lg font-semibold text-slate-800 mb-4">选择区域</h3>
                    
                    <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4">
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center selected">
                            <i class="fas fa-map-marker-alt text-2xl text-indigo-600 mb-2"></i>
                            <h4 class="font-medium text-slate-800">福田区</h4>
                            <p class="text-sm text-slate-500 mt-1">156 件</p>
                        </div>
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center">
                            <i class="fas fa-map-marker-alt text-2xl text-slate-400 mb-2"></i>
                            <h4 class="font-medium text-slate-800">罗湖区</h4>
                            <p class="text-sm text-slate-500 mt-1">134 件</p>
                        </div>
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center">
                            <i class="fas fa-map-marker-alt text-2xl text-slate-400 mb-2"></i>
                            <h4 class="font-medium text-slate-800">南山区</h4>
                            <p class="text-sm text-slate-500 mt-1">189 件</p>
                        </div>
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center">
                            <i class="fas fa-map-marker-alt text-2xl text-slate-400 mb-2"></i>
                            <h4 class="font-medium text-slate-800">宝安区</h4>
                            <p class="text-sm text-slate-500 mt-1">223 件</p>
                        </div>
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center">
                            <i class="fas fa-map-marker-alt text-2xl text-slate-400 mb-2"></i>
                            <h4 class="font-medium text-slate-800">龙岗区</h4>
                            <p class="text-sm text-slate-500 mt-1">198 件</p>
                        </div>
                        <div class="region-card border-2 border-slate-200 rounded-lg p-4 text-center">
                            <i class="fas fa-map-marker-alt text-2xl text-slate-400 mb-2"></i>
                            <h4 class="font-medium text-slate-800">盐田区</h4>
                            <p class="text-sm text-slate-500 mt-1">89 件</p>
                        </div>
                    </div>
                </div>

                <!-- 分析结果 -->
                <div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
                    <!-- 区域数量对比 -->
                    <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
                        <div class="flex items-center justify-between mb-6">
                            <h3 class="text-lg font-semibold text-slate-800">区域信访数量对比</h3>
                            <div class="flex space-x-2">
                                <button class="px-3 py-1 text-sm bg-indigo-100 text-indigo-700 rounded-lg">柱状图</button>
                                <button class="px-3 py-1 text-sm hover:bg-slate-100 rounded-lg">折线图</button>
                            </div>
                        </div>
                        <div class="chart-container">
                            <canvas id="regionChart"></canvas>
                        </div>
                    </div>

                    <!-- 污染类型占比 -->
                    <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
                        <div class="flex items-center justify-between mb-6">
                            <h3 class="text-lg font-semibold text-slate-800">福田区污染类型占比</h3>
                            <select class="text-sm border border-slate-300 rounded-lg px-3 py-1 focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <option>福田区</option>
                                <option>罗湖区</option>
                                <option>南山区</option>
                                <option>宝安区</option>
                                <option>龙岗区</option>
                                <option>盐田区</option>
                            </select>
                        </div>
                        <div class="chart-container">
                            <canvas id="pollutionChart"></canvas>
                        </div>
                    </div>
                </div>

                <!-- 详细统计 -->
                <div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
                    <h3 class="text-lg font-semibold text-slate-800 mb-6">区域详细统计</h3>
                    
                    <div class="overflow-x-auto">
                        <table class="w-full">
                            <thead class="bg-slate-50">
                                <tr>
                                    <th class="text-left p-4 font-semibold text-slate-700">区域</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">信访总数</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">已处理</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">处理中</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">待处理</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">处理率</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">平均处理时长</th>
                                    <th class="text-left p-4 font-semibold text-slate-700">满意度</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-slate-200">
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-indigo-600 rounded-full"></div>
                                            <span class="font-medium">福田区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">156</td>
                                    <td class="p-4 text-green-600">112</td>
                                    <td class="p-4 text-yellow-600">32</td>
                                    <td class="p-4 text-red-600">12</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 71.8%"></div>
                                            </div>
                                            <span class="text-sm">71.8%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">4.8天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.5</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-blue-600 rounded-full"></div>
                                            <span class="font-medium">罗湖区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">134</td>
                                    <td class="p-4 text-green-600">98</td>
                                    <td class="p-4 text-yellow-600">28</td>
                                    <td class="p-4 text-red-600">8</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 73.1%"></div>
                                            </div>
                                            <span class="text-sm">73.1%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">5.2天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.3</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-green-600 rounded-full"></div>
                                            <span class="font-medium">南山区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">189</td>
                                    <td class="p-4 text-green-600">145</td>
                                    <td class="p-4 text-yellow-600">36</td>
                                    <td class="p-4 text-red-600">8</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 76.7%"></div>
                                            </div>
                                            <span class="text-sm">76.7%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">4.5天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.6</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-yellow-600 rounded-full"></div>
                                            <span class="font-medium">宝安区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">223</td>
                                    <td class="p-4 text-green-600">156</td>
                                    <td class="p-4 text-yellow-600">45</td>
                                    <td class="p-4 text-red-600">22</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 69.9%"></div>
                                            </div>
                                            <span class="text-sm">69.9%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">5.5天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.2</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-purple-600 rounded-full"></div>
                                            <span class="font-medium">龙岗区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">198</td>
                                    <td class="p-4 text-green-600">142</td>
                                    <td class="p-4 text-yellow-600">38</td>
                                    <td class="p-4 text-red-600">18</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 71.7%"></div>
                                            </div>
                                            <span class="text-sm">71.7%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">5.1天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.4</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr class="hover:bg-slate-50">
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-3 h-3 bg-red-600 rounded-full"></div>
                                            <span class="font-medium">盐田区</span>
                                        </div>
                                    </td>
                                    <td class="p-4 font-medium">89</td>
                                    <td class="p-4 text-green-600">68</td>
                                    <td class="p-4 text-yellow-600">15</td>
                                    <td class="p-4 text-red-600">6</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-2">
                                            <div class="w-20 bg-slate-200 rounded-full h-2">
                                                <div class="bg-green-500 h-2 rounded-full" style="width: 76.4%"></div>
                                            </div>
                                            <span class="text-sm">76.4%</span>
                                        </div>
                                    </td>
                                    <td class="p-4">4.2天</td>
                                    <td class="p-4">
                                        <div class="flex items-center space-x-1">
                                            <i class="fas fa-star text-yellow-400 text-sm"></i>
                                            <span class="text-sm">4.7</span>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script>
        // 侧边栏折叠功能
        const sidebar = document.getElementById('sidebar');
        const sidebarToggle = document.getElementById('sidebarToggle');
        const fadeTexts = document.querySelectorAll('.fade-text');

        sidebarToggle.addEventListener('click', () => {
            const isCollapsed = sidebar.classList.contains('sidebar-collapsed');

            sidebar.classList.toggle('sidebar-collapsed');
            sidebar.classList.toggle('sidebar-expanded');

            setTimeout(() => {
                fadeTexts.forEach(text => {
                    if (sidebar.classList.contains('sidebar-collapsed')) {
                        text.classList.add('hidden');
                    } else {
                        text.classList.remove('hidden');
                    }
                });
            }, isCollapsed ? 0 : 200);
        });

        // 用户菜单
        const userMenuBtn = document.getElementById('userMenuBtn');
        const userMenu = document.getElementById('userMenu');

        userMenuBtn.addEventListener('click', () => {
            userMenu.classList.toggle('hidden');
        });

        // 点击外部关闭菜单
        document.addEventListener('click', (e) => {
            if (!userMenuBtn.contains(e.target) && !userMenu.contains(e.target)) {
                userMenu.classList.add('hidden');
            }
        });

        // 区域选择
        const regionCards = document.querySelectorAll('.region-card');
        regionCards.forEach(card => {
            card.addEventListener('click', () => {
                regionCards.forEach(c => c.classList.remove('selected'));
                card.classList.add('selected');
                // 更新图表数据
                updateCharts();
            });
        });

        // 时间标签切换
        const timeTags = document.querySelectorAll('.time-tag');
        timeTags.forEach(tag => {
            tag.addEventListener('click', () => {
                timeTags.forEach(t => t.classList.remove('active'));
                tag.classList.add('active');
            });
        });

        // 区域数量对比图
        const regionCtx = document.getElementById('regionChart').getContext('2d');
        const regionChart = new Chart(regionCtx, {
            type: 'bar',
            data: {
                labels: ['福田区', '罗湖区', '南山区', '宝安区', '龙岗区', '盐田区'],
                datasets: [{
                    label: '信访数量',
                    data: [156, 134, 189, 223, 198, 89],
                    backgroundColor: [
                        'rgba(99, 102, 241, 0.8)',
                        'rgba(59, 130, 246, 0.8)',
                        'rgba(34, 197, 94, 0.8)',
                        'rgba(245, 158, 11, 0.8)',
                        'rgba(168, 85, 247, 0.8)',
                        'rgba(239, 68, 68, 0.8)'
                    ],
                    borderColor: [
                        'rgb(99, 102, 241)',
                        'rgb(59, 130, 246)',
                        'rgb(34, 197, 94)',
                        'rgb(245, 158, 11)',
                        'rgb(168, 85, 247)',
                        'rgb(239, 68, 68)'
                    ],
                    borderWidth: 2,
                    borderRadius: 8,
                    borderSkipped: false,
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    },
                    tooltip: {
                        backgroundColor: 'rgba(0, 0, 0, 0.8)',
                        titleColor: '#fff',
                        bodyColor: '#fff',
                        borderColor: '#fff',
                        borderWidth: 1,
                        cornerRadius: 8,
                        callbacks: {
                            label: function(context) {
                                return '信访数量: ' + context.parsed.y + ' 件';
                            }
                        }
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        grid: {
                            color: 'rgba(0, 0, 0, 0.05)'
                        }
                    },
                    x: {
                        grid: {
                            display: false
                        }
                    }
                }
            }
        });

        // 污染类型占比图
        const pollutionCtx = document.getElementById('pollutionChart').getContext('2d');
        const pollutionChart = new Chart(pollutionCtx, {
            type: 'doughnut',
            data: {
                labels: ['环境污染', '噪音扰民', '市容管理', '交通问题', '其他'],
                datasets: [{
                    data: [45, 32, 28, 20, 31],
                    backgroundColor: [
                        'rgb(239, 68, 68)',
                        'rgb(245, 158, 11)',
                        'rgb(34, 197, 94)',
                        'rgb(59, 130, 246)',
                        'rgb(156, 163, 175)'
                    ],
                    borderWidth: 2,
                    borderColor: '#fff'
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        position: 'bottom',
                        labels: {
                            padding: 15,
                            font: {
                                size: 12
                            }
                        }
                    },
                    tooltip: {
                        backgroundColor: 'rgba(0, 0, 0, 0.8)',
                        titleColor: '#fff',
                        bodyColor: '#fff',
                        borderColor: '#fff',
                        borderWidth: 1,
                        cornerRadius: 8,
                        callbacks: {
                            label: function(context) {
                                const label = context.label || '';
                                const value = context.parsed || 0;
                                const total = context.dataset.data.reduce((a, b) => a + b, 0);
                                const percentage = ((value / total) * 100).toFixed(1);
                                return label + ': ' + value + ' (' + percentage + '%)';
                            }
                        }
                    }
                },
                cutout: '60%'
            }
        });

        // 更新图表函数
        function updateCharts() {
            // 这里可以根据选择的区域更新图表数据
            console.log('更新图表数据');
        }
    </script>
</body>
</html>